package com.fdm.model.accounts;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import com.fdm.model.exceptions.BankManagerException;
import com.fdm.model.exceptions.BankPropertiesException;

public class AccountBuilder 
{	
	public _Account buildAccountComposite(String [] decorations,
			Map<String,Object> parameters) throws BankManagerException
	{
		_Account account = new ConcreteAccount();
		account.setAttributes(parameters);
		Class<?>[] arg = {_Account.class};
		for (String decoration : decorations)
		{
			try {
				account = (_Account) Class.forName(
						decoration).getConstructor(arg).newInstance(account);
			} catch (IllegalArgumentException e) {
				throw new BankPropertiesException();
			} catch (SecurityException e) {
				throw new BankPropertiesException();
			} catch (InstantiationException e) {
				throw new BankPropertiesException();
			} catch (IllegalAccessException e) {
				throw new BankPropertiesException();
			} catch (InvocationTargetException e) {
				throw new BankPropertiesException();
			} catch (ClassNotFoundException e) {
				throw new BankPropertiesException();
			} catch (NoSuchMethodException e) {
				throw new BankPropertiesException();
			}
			account.setAttributes(parameters);
		}
		return account;
	}
}
